package org.millioncall.yueyoga.admin.dao.impl;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.millioncall.openplatform.dao.support.spring.SpringJdbcDAOHelper;
import org.millioncall.yueyoga.admin.dao.BaseDao;
import org.millioncall.yueyoga.admin.dao.StatisticsDAO;
import org.springframework.jdbc.core.RowMapper;

/**
 * 信息统计实现类
 * 
 * @author lishoujing
 * @version 1.0.0
 * 
 */
public class StatisticsDAOImpl extends BaseDao implements StatisticsDAO {

	private SpringJdbcDAOHelper springJdbcDAOHelper;

	public void setSpringJdbcDAOHelper(SpringJdbcDAOHelper springJdbcDAOHelper) {
		this.springJdbcDAOHelper = springJdbcDAOHelper;
	}

	@Override
	public List<Object[]> commonStat(String sql, Map<String, Object> params) {
		return this.springJdbcDAOHelper.getNamedJdbcTemplate().query(sql,
				params, new RowMapper<Object[]>() {
					@Override
					public Object[] mapRow(ResultSet arg0, int arg1)
							throws SQLException {
						int cols = arg0.getMetaData().getColumnCount();
						Object[] rtn = new Object[cols];
						for (int i = 0; i < cols; i++) {
							rtn[i] = arg0.getObject(i + 1);
						}
						return rtn;
					}
				});
	}
}
